package pt.ipleiria.plp.ui;

import de.enough.polish.ui.Alert;
import de.enough.polish.ui.AlertType;
import de.enough.polish.ui.Command;
import de.enough.polish.ui.Displayable;
import de.enough.polish.util.Locale;

import pt.ipleiria.plp.BlackSpotterMidlet;

/**
 *
 * @author Ricardo
 */
public class CriarEventoScreen extends EventoScreen {

    public CriarEventoScreen(BlackSpotterMidlet midlet) {
        super(midlet, Locale.get("title.NovaLixeira"),null);

        createTabs(true);
    }

    public void commandAction(Command c, Displayable d) {

        if (c == getCmdExit()) {
            //#style popupAlert
            Alert alert = new Alert(Locale.get("title.noSave"),
                    Locale.get("mensagens.noSaveCreate"), null, AlertType.CONFIRMATION);
            alert.addCommand(getCmdNao());
            alert.addCommand(getCmdSim());
            alert.setCommandListener(this);
            getMidlet().getDisplay().setCurrent(alert);
        } else if (c == getCmdNao()) {
            getMidlet().getDisplay().setCurrent(this);
        }
        if (c == getCmdSim()) {
            getMidlet().getDisplay().setCurrent(getMidlet().getMainMenu());
        } else if (c == getCmdProx()) {
            int valid = validateFields();
            if (valid == 0) {

                if (getMidlet().getApp().getManager().criarNovaLixeira(getLixTitle(),
                        getPos()[0], getPos()[1], getTam(), getCatLix(), getNumVolunteers(),
                        getEstVolume(), getDescBox(), getTagsList(), getFotos())) {

                    Alert alert = new Alert(Locale.get("title.sucesso"),
                            Locale.get("mensagens.sucesso"), null, AlertType.INFO);
                    getMidlet().getDisplay().setCurrent(alert, getMidlet().getMainMenu());

                }

            } else {

                String error = null;

                switch (valid) {
                    case 1:
                        error = Locale.get("newEv.pos");
                        break;
                    case 2:
                        error = Locale.get("newEv.desc");
                        break;
                    case 3:
                        error = Locale.get("cats.title");
                        break;
                    case 4:
                        error = Locale.get("mensagens.tags");
                        break;
                    case 5:
                        error = Locale.get("newEv.volume");
                        break;
                    case 6:
                        error = Locale.get("newEv.numero");
                        break;
                    default:
                        error = "BUG!";
                        break;
                }
                Alert alert = new Alert(Locale.get("title.camposFalta"),
                        Locale.get("mensagens.camposFalta") + error, null, AlertType.WARNING);
                getMidlet().getDisplay().setCurrent(alert, this);

            }
        } else {
            super.commandAction(c, d);
        }

    }


    



}
